package applet;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Frame;

import org.pushingpixels.substance.api.skin.*;

import sql.SQLInterface;

import applet.view.CMSViewController;

import com.meg.swing_utils.SwingInvoker;
import com.meg.swing_utils.laf.LookAndFeel;

import data.CMSRes;

public class CMSApplet extends Applet
{
	private static final long serialVersionUID = -2361744333811174112L;
	
	private Frame getFrame()
	{
		Container c = this; 
		while(c != null)
	    { 
	    	if (c instanceof Frame) 
	    	  return (Frame)c;
	    	c = c.getParent(); 
	    }
	    return (Frame) null;
	}
	
	public final void init()
	{
		new CMSAppletInvoker(this).start();
	}
	
	protected class CMSAppletInvoker extends SwingInvoker
	{
		private CMSApplet applet;
		
		public CMSAppletInvoker(CMSApplet applet)
		{
			this.applet = applet;
		}
		
		public void run()
		{
			LookAndFeel.enableDecoration(true);
			LookAndFeel.Substance.init(new OfficeBlack2007Skin());
			
			CMSRes.init(applet.getFrame());
			SQLInterface.initDatabase();
			setLayout(new BorderLayout());
			add(new CMSViewController(), BorderLayout.CENTER);
		}
	}
}